import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { User } from '../entities/user.entity';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class UserService {
  constructor(
    @InjectRepository(User)
    private readonly userRepository: Repository<User>,
  ) {}

  getHello(): string {
    return 'Hello World!';
  }

  login() {
    return 'Login successful!';
  }

  findOneInfo(id: string) {
    return 'www' + id;
  }

  findAll(pageSize: number, pageNum: number) {
    return this.userRepository.find({
      skip: (pageNum - 1) * pageSize,
      take: pageSize,
    });
  }

  async create(user: Partial<User>): Promise<User> {
    return this.userRepository.save(user);
  }
}
